﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using ORS.BLL;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ORS.Web
{
    public partial class User_Mainpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e) 
        {


        }

        protected void UserFileAdd(object sender, EventArgs e)
        {


            if (tbx_title.Text.Trim() == "" || FileUpload1.FileName == "")
            {
                Label2.Visible = true;
                Label3.Visible = false;
                Label4.Visible = false;
            }
            else if(FileUpload1.FileName.Length >=20){
                Label2.Visible = false;
                Label3.Visible = true;
                Label4.Visible = false;
            }
            else if (FileUpload1.PostedFile.ContentLength >= 1024 * 1024 || FileUpload1.PostedFile.ContentLength == 0)
            {
                Label2.Visible = false;
                Label3.Visible = false;
                Label4.Visible = true;
            }
            else
            {
                //构造book信息哈希表
                Hashtable ht = new Hashtable();
                //标题
                //ht.Add("paperid",111);
                ht.Add("tiltle", "'" + tbx_title.Text.Trim() + "'");
                //作者
                ht.Add("authorid", "'" + Session["userid"].ToString().Trim() + "'");
                //领域
                ht.Add("interestid", DropDownList1.SelectedItem.Value.Trim());
                //submitdate
                ht.Add("submitdate", "'" + DateTime.Now.ToString("d") + "'");
                ht.Add("sublimitdate", "'" + DateTime.Now.AddDays(15).ToString("d") + "'");
                //表述
                string htmlContent = System.Web.HttpUtility.HtmlEncode(tbx_interest0.Text);
                htmlContent = htmlContent.Replace(((char)13).ToString(), "<br>");	//将"\t"替换为回车"<br>"
                ht.Add("description", "'" + htmlContent + "'");
                ht.Add("reviewer", "'暂未指定'");
                //附件名,以当前时间为文件名前缀,确保文件名没有重复
                string affixFileName = FileUpload1.FileName;
                int idx = affixFileName.LastIndexOf('\\');
                affixFileName = affixFileName.Substring(idx + 1);
                string fileName = "";
                if (affixFileName != "")
                {
                    //Ticks属性的值为自 0001 年 1 月 1 日午夜 12:00 以来所经过时间以 100 毫微秒为间隔表示时的数字。
                    fileName = ".\\Papers\\" + System.DateTime.Now.Ticks.ToString() + "@_@" + affixFileName;
                    ht.Add("contentlink", "'" + fileName + "'");
                }

                ht.Add("reviewstate", 0);	//未审阅

                ////添加文稿,如果数据类型不正确,给出提示.
                //ArrayList WarningMessageList=new ArrayList();
                //LabelWarningMessage.Text="";
                //if(FileHelper.Add(ht,ref WarningMessageList)==false)
                //{
                //    LabelWarningMessage.Text="<font color=red>";
                //    foreach(string item in WarningMessageList)
                //    {
                //        LabelWarningMessage.Text+=item+"<br>";
                //    }
                //    LabelWarningMessage.Text+="</font>";
                //}

                //上传附件
                String TableName = "[tb_paperinfo]";
                if (fileName != "")
                {
                    FileUpload1.PostedFile.SaveAs(Server.MapPath(".") + fileName);
                    Paper.AddPaperInfo(TableName, ht);
                    Emailsend es = new Emailsend();
                    String EmailAdd = es.getEmailAd(Session["userid"].ToString().Trim());
                    es.SendTo(EmailAdd, "ORSmail-在线审稿", "您的文章《" + tbx_title.Text.Trim() + "》已成功上传，正在待审中！");
                }
                Response.Redirect("UpLoadOk.aspx");
            }

      }

        //protected void Button2_Click(object sender, EventArgs e)
        //{
        //    //Response.Redirect("login.aspx");
        //    Emailsend es = new Emailsend();
        //    es.SendTo("weishenglong405@163.com", "ORS自动提示", "您的文章已成功上传，正在待审中！");

        //}

        protected void LinkButton1_Click1(object sender, EventArgs e)
        {
            Response.Redirect("login.aspx");
        }
    }
}